import { _decorator, Color, Component, Node, Sprite, SpriteFrame, UITransform } from 'cc'
const { ccclass, property } = _decorator

/**背包格子 */

@ccclass('BagGrilditem')
export class BagGrilditem extends Component {
  /** 状态：0，可放置，1，不可放置 */
  public m_state = 0
  /**放置的物品类型 */
  public m_type = -1
  private _x = 0

  private _y = 0
  protected ItemName: string = ''
  public get x() {
    return this._x
  }
  public get y() {
    return this._y
  }
  public set x(value) {
    this._x = value
  }
  public set y(value) {
    this._y = value
  }
  private items: BagGrilditem[] = []
  private grid: Map<string, BagGrilditem> = new Map()
  public create(x: number, y: number, name: string) {
    this.x = x
    this.y = y
    this.m_state = 0
    this.node.name = name
    this.node.getChildByName('Node').active = false
  }

  getItemPosition() {
    return { x: this.node.getPosition().x, y: this.node.getPosition().y }
  }

  setColor() {
    //设置全黑
    this.node.getComponent(Sprite).color = new Color(0, 0, 0, 255)
  }

  setSelectBgAct(value: boolean) {
    this.node.getChildByName('Node').active = value
  }
  // 添加物品到指定格子
  addItemToGrid(type: number) {
    this.m_type = type
  }

  // 获取指定格子的物品
  getItemFromGrid(): Number {
    return this.m_type
  }
  start() {}

  update(deltaTime: number) {}
}
